const db= require('../../db/index');
const path=require('path');
let editarticle=(req,res)=>{
    const sqlStr=`select * from ev_articles where Id=?`
    db.query(sqlStr,req.body.id,(err,results)=>{
        if (err) return res.cc(err);
        if(results.length!==1) return res.cc('没有这篇文章')
        const articleInfo ={
            ...req.body,
            cover_img: path.join('/uploads', req.file.filename),
            pub_date: new Date(),
            author_id: req.user.id
        }
        const sqlStr=`update ev_articles set ?  where Id=?`
        db.query(sqlStr,[articleInfo,req.body.id],(err,results)=>{
            if (err) return res.cc(err)
            if (results.affectedRows!==1) return res.cc('修改失败');
            res.cc('修改成功',0)
        })
    })
    
}
module.exports =editarticle
